let yashuUtil = require("./yashu-util.js");
/* -------------------------------------------------------------------------- */
function FloatingWindow(queue) {
  yashuUtil.printObj(floaty);
  let that = this;
  threads.start(function () {
    that.window = floaty.rawWindow(
      <vertical bg="#99263238">
        <text id="queueContent" textColor="#ffffff"></text>
        <list id="list" h="300dp" alpha="1">
          <horizontal padding="16">
            <text text="{{this.groupName}} --- " textColor="#ffffff"></text>
            <text text="{{this.message}}" textColor="#ffffff"></text>
          </horizontal>
        </list>
      </vertical>
    );
    ui.run(function () {
      that.window.queueContent.setFocusable(true);
    });
    setInterval(() => {
      ui.run(function () {
        // that.window.queueContent.setText("queue: " + JSON.stringify(queue));
      });
    }, 1000);
    that.window.setTouchable(false);
    let listView = that.window.list;
    ui.run(function () {
      listView.setDataSource(queue);
      that.window.setPosition(0, 0);
    });
    events.on("exit", function () {
      if (that.window) {
        that.window.close();
        that.window = null;
        console.log("释放资源: window");
      }
    });
  });
}
FloatingWindow.prototype.show = function () {
  console.log("show");
};
FloatingWindow.prototype.hide = function () {
  console.log("hide");
};
FloatingWindow.prototype.toggleFocus = function () {
  let that = this;
  threads.start(function () {
    ui.run(function () {
      let w = that.window;
      w.requestFocus();
      w.queueContent.requestFocus();
      ui.post(function () {
        w.queueContent.clearFocus();
        w.disableFocus();
      }, 200);
    });
  });
  sleep(300);
};

module.exports = FloatingWindow;
